Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding flavor as a has one on VM #17692

Merged
merged 1 commit into from
Jul 18, 2018

Conversation

juliancheal
Copy link
Member

@juliancheal juliancheal commented Jul 11, 2018

I basically want to search Vms like
vms = Flavor.joins(:vms).where(:flavors => {:name => 't2.micro'})

so that in the api we can filter by flavor name

http://localhost:3000/api/vms?filter[]=flavor.name='t2.micro'

Fixes BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1596069

@miq-bot miq-bot added the wip label Jul 11, 2018
@juliancheal juliancheal force-pushed the filter_by_flavor_api branch 3 times, most recently from bf256e7 to d515e53 Compare July 11, 2018 15:08
@juliancheal
Copy link
Member Author

@miq-bot assign @gtanzillo

@juliancheal
Copy link
Member Author

juliancheal commented Jul 11, 2018

This seems to be almost generating the correct query.

But I don't want flavours.id to equal vms.id and flavours.name is twice at the end :(

SELECT DISTINCT COUNT(DISTINCT "vms"."id") FROM "vms"
LEFT OUTER JOIN "flavors" ON "flavors"."id" = "vms"."id" AND "flavors"."name" = $1
WHERE "vms"."type" IN ('Vm', 'VmServer', 'ManageIQ::Providers::InfraManager::Vm', 'ManageIQ::Providers::CloudManager::Vm', 'VmXen',
'ManageIQ::Providers::Kubevirt::InfraManager::Vm',
'ManageIQ::Providers::Redhat::InfraManager::Vm',
'ManageIQ::Providers::Microsoft::InfraManager::Vm',
'ManageIQ::Providers::Vmware::InfraManager::Vm',
'ManageIQ::Providers::Amazon::CloudManager::Vm', 
'ManageIQ::Providers::Azure::CloudManager::Vm', 
'ManageIQ::Providers::Google::CloudManager::Vm',
'ManageIQ::Providers::Openstack::CloudManager::Vm',
'ManageIQ::Providers::Vmware::CloudManager::Vm') 
AND "vms"."template" = $2 
AND ("flavors"."name" = 't2.micro') 
AND ("flavors"."name" = 't2.micro')

Running Flavor.joins(:vms).where(:flavors => {:name => 't2.micro'}).to_sql

produces this

"SELECT \"flavors\".* FROM \"flavors\" INNER JOIN \"vms\" 
ON \"vms\".\"flavor_id\" = \"flavors\".\"id\" 
AND \"vms\".\"type\" IN ('Vm', 'VmServer',
'ManageIQ::Providers::InfraManager::Vm',
'ManageIQ::Providers::CloudManager::Vm',
'VmXen',
'ManageIQ::Providers::Kubevirt::InfraManager::Vm',
'ManageIQ::Providers::Redhat::InfraManager::Vm',
'ManageIQ::Providers::Microsoft::InfraManager::Vm',
'ManageIQ::Providers::Vmware::InfraManager::Vm',
'ManageIQ::Providers::Amazon::CloudManager::Vm',
'ManageIQ::Providers::Azure::CloudManager::Vm',
'ManageIQ::Providers::Google::CloudManager::Vm',
'ManageIQ::Providers::Openstack::CloudManager::Vm',
'ManageIQ::Providers::Vmware::CloudManager::Vm') 
AND \"vms\".\"template\" = 'f' WHERE \"flavors\".\"name\" = 't2.micro'" 

Which is more what I was hopping would happen from adding https://github.com/ManageIQ/manageiq/pull/17692/files#diff-fb7c3f0121965870e99fe02ec498cf65R63

Update

Think this might be it

SELECT DISTINCT COUNT(DISTINCT "vms"."id")
FROM "vms" LEFT OUTER JOIN "flavors" 
ON "flavors"."ems_id" = "vms"."id" WHERE "vms"."type" IN ('Vm', 'VmServer', 
  'ManageIQ::Providers::InfraManager::Vm',
  'ManageIQ::Providers::CloudManager::Vm', 'VmXen', 
  'ManageIQ::Providers::Kubevirt::InfraManager::Vm',
  'ManageIQ::Providers::Redhat::InfraManager::Vm',
  'ManageIQ::Providers::Microsoft::InfraManager::Vm', 
  'ManageIQ::Providers::Vmware::InfraManager::Vm', 
  'ManageIQ::Providers::Amazon::CloudManager::Vm',
  'ManageIQ::Providers::Azure::CloudManager::Vm',
  'ManageIQ::Providers::Google::CloudManager::Vm', 
  'ManageIQ::Providers::Openstack::CloudManager::Vm', 
  'ManageIQ::Providers::Vmware::CloudManager::Vm') 
AND "vms"."template" = $1 
AND ("flavors"."name" = 't2.micro') 
AND ("flavors"."name" = 't2.micro') 

@miq-bot
Copy link
Member

miq-bot commented Jul 18, 2018

Checked commit juliancheal@fdc4166 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
1 file checked, 0 offenses detected
Everything looks fine. 🏆

@juliancheal juliancheal changed the title [WIP] Adding flavor as a has one on VM Adding flavor as a has one on VM Jul 18, 2018
@miq-bot miq-bot removed the wip label Jul 18, 2018
@gtanzillo gtanzillo added this to the Sprint 91 Ending Jul 30, 2018 milestone Jul 18, 2018
@gtanzillo gtanzillo merged commit fb7a26d into ManageIQ:master Jul 18, 2018
@simaishi
Copy link
Contributor

@juliancheal @gtanzillo Can this be gaprindashvili/yes and fine/yes?

@juliancheal
Copy link
Member Author

@simaishi Yes, I think so.

simaishi pushed a commit that referenced this pull request Jul 23, 2018
@simaishi
Copy link
Contributor

Gaprindashvili backport details:

$ git log -1
commit 54ec113077d242bb804770698601291a040deb80
Author: Gregg Tanzillo <gtanzill@redhat.com>
Date:   Wed Jul 18 16:46:18 2018 -0400

    Merge pull request #17692 from juliancheal/filter_by_flavor_api
    
    Adding flavor as a has one on VM
    (cherry picked from commit fb7a26da221d315639bf6851d646522db54f5d17)
    
    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1607441

simaishi pushed a commit that referenced this pull request Aug 14, 2018
@simaishi
Copy link
Contributor

Fine backport details:

$ git log -1
commit 937f733bbe21cf6bd99b46155f3b27eaab78cd99
Author: Gregg Tanzillo <gtanzill@redhat.com>
Date:   Wed Jul 18 16:46:18 2018 -0400

    Merge pull request #17692 from juliancheal/filter_by_flavor_api
    
    Adding flavor as a has one on VM
    (cherry picked from commit fb7a26da221d315639bf6851d646522db54f5d17)
    
    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1607442

tumido pushed a commit to tumido/manageiq that referenced this pull request Aug 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants